package lg.minecraft.plugin.library.command;

import lg.minecraft.plugin.library.config.message.LGPluginMessage;
import org.bukkit.command.CommandSender;

/**
 * @author langle__
 * @version 1.0
 */
public class HelpCommand extends SubCommand {

    private final String permission;

    public HelpCommand(String permission) {
        super("help");
        this.permission = permission;
    }

    public HelpCommand() {
        this(null);
    }

    @Override
    public String getDescription() {
        return "命令查询";
    }

    @Override
    public String getPermission() {
        return this.permission;
    }

    @Override
    public void onCommand(CommandContext context) {
        CommandSender sender = context.getSender();
        LGCommand parentCommand = this.getParentCommand();
        if (parentCommand == null) return;
        LGPluginMessage message = parentCommand.getPlugin().getLGMessage();
        String alias = parentCommand.getAlias();
        for (SubCommand command : parentCommand.getSubCommands()) {
            sender.sendMessage(message.getHelp(alias, command.getName(), command.getDescription()));
        }
    }

}
